package com.ysy.tz.core.selfcomp;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.Node;
import javafx.scene.control.ToggleButton;
import javafx.scene.image.ImageView;

public class CustomerToggleButton extends ToggleButton {
    private ObjectProperty<ImageView> selectImage = new SimpleObjectProperty();
    private ObjectProperty<ImageView> normalImage = new SimpleObjectProperty();

    public CustomerToggleButton() {
        this.selectedProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue) {
                if (this.selectImage.get() != null) {
                    this.setGraphic((Node)this.selectImage.get());
                }
            } else if (this.normalImage.get() != null) {
                this.setGraphic((Node)this.normalImage.get());
            }

        });
        this.setOnMouseReleased((mouseEvent) -> {
            if (!this.isSelected()) {
                this.setSelected(true);
            }

        });
    }

    public ImageView getSelectImage() {
        return (ImageView)this.selectImage.get();
    }

    public ObjectProperty<ImageView> selectImageProperty() {
        return this.selectImage;
    }

    public void setSelectImage(ImageView selectImage) {
        this.selectImage.set(selectImage);
    }

    public ImageView getNormalImage() {
        return (ImageView)this.normalImage.get();
    }

    public ObjectProperty<ImageView> normalImageProperty() {
        return this.normalImage;
    }

    public void setNormalImage(ImageView normalImage) {
        this.setGraphic(normalImage);
        this.normalImage.set(normalImage);
    }
}
